home *** CD-ROM | disk | FTP | other *** search
- Path: news1.sunbelt.net!dial-13
- From: dking@SunBelt.Net
- Newsgroups: comp.lang.c
- Subject: accessing structures (newbie question)
- Date: 19 Feb 1996 00:34:20 GMT
- Organization: SunBelt.Net INTERNET Access
- Message-ID: <4g8gic$o6u@news1.sunbelt.net>
- NNTP-Posting-Host: dial-13.r1.gaagst.sunbelt.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- Ok. having trouble accessing structure. here I define a pointer and malloc the
- memory:
-
- struct picture *photos;
- photos = (struct picture *)malloc(1000 * sizeof(picture));
-
- now I try to store data into structures...
-
- for (x=0;x<num_of_files;x++)
- {
- strncpy(photos->filename, filelist[x],12);
- strncpy(photos->diskname, inputdisk,12);
- strncpy(photos->indexname, inputindex,12);
- }
-
- now I try to read data...
-
-
- for (x=0;x<num_of_files;x++)
- {
-
- printf("%sdisk%sindex%s\n",photos->filename,photos->diskname,photos->indexname
- ; }
-
- Obviously I'm pointing to the first of the 1000 structures the entire time.
- Now for the 60,000 dollar question: HOW do I access the rest of the
- structures? My tutuorial doesnt have any examples of accessing MALLOCed
- structures. The one example on structures defines it as an array (struct
- picture *photos[x] ) but 1000 elements is too large an array and the example
- with malloc uses floating point data accessed by using (photos[x]) which
- doesnt work either with the strnccpy or with the -> operator.
-
- I'd Appreciate any assistance you might offer.
-
- Daryl
-